package com.muyu.danmo.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.danmo.domain.DanmoAssociationType;
import com.muyu.danmo.domain.DanmoInformation;
import com.muyu.danmo.mapper.DanmoAssociationTypeMapper;
import com.muyu.danmo.mapper.DanmoInformationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.muyu.danmo.mapper.DanmoInformationMapMapper;
import com.muyu.danmo.domain.DanmoInformationMap;
import com.muyu.danmo.service.IDanmoInformationMapService;

/**
 * 个人信息相关星图Service业务层处理
 *
 * @author kunzong
 * @date 2024-11-30
 */
@Service
public class DanmoInformationMapServiceImpl extends ServiceImpl<DanmoInformationMapMapper, DanmoInformationMap> implements IDanmoInformationMapService {
    @Autowired
    private DanmoInformationMapMapper danmoInformationMapMapper;

    @Autowired
    private DanmoInformationMapper danmoInformationMapper;

    /**
     * 查询个人信息相关星图
     *
     * @param id 个人信息相关星图主键
     * @return 个人信息相关星图
     */
    @Override
    public DanmoInformationMap selectDanmoInformationMapById(Long id) {
        return danmoInformationMapMapper.selectDanmoInformationMapById(id);
    }

    /**
     * 查询个人信息相关星图列表
     *
     * @param danmoInformationMap 个人信息相关星图
     * @return 个人信息相关星图
     */
    @Override
    public List<DanmoInformationMap> selectDanmoInformationMapList(DanmoInformationMap danmoInformationMap) {
        return danmoInformationMapMapper.selectDanmoInformationMapList(danmoInformationMap);
    }

    /**
     * 新增个人信息相关星图
     *
     * @param danmoInformationMap 个人信息相关星图
     * @return 结果
     */
    @Override
    public int insertDanmoInformationMap(DanmoInformationMap danmoInformationMap) {

        return danmoInformationMapMapper.insertDanmoInformationMap(danmoInformationMap);
    }

    /**
     * 修改个人信息相关星图
     *
     * @param danmoInformationMap 个人信息相关星图
     * @return 结果
     */
    @Override
    public int updateDanmoInformationMap(DanmoInformationMap danmoInformationMap) {
        return danmoInformationMapMapper.updateDanmoInformationMap(danmoInformationMap);
    }

    /**
     * 批量删除个人信息相关星图
     *
     * @param ids 需要删除的个人信息相关星图主键
     * @return 结果
     */
    @Override
    public int deleteDanmoInformationMapByIds(Long[] ids) {
        return danmoInformationMapMapper.deleteDanmoInformationMapByIds(ids);
    }

    /**
     * 删除个人信息相关星图信息
     *
     * @param id 个人信息相关星图主键
     * @return 结果
     */
    @Override
    public int deleteDanmoInformationMapById(Long id) {
        return danmoInformationMapMapper.deleteDanmoInformationMapById(id);
    }

    /**
     * 根据信息id查询个人信息相关星图
     *
     * @param informationId
     * @return
     */
    @Override
    public List<DanmoInformationMap> selectDanmoInformationMapByInformationId(Long informationId) {
        List<DanmoInformationMap> danmoInformationMaps = danmoInformationMapMapper.selectDanmoInformationMapByInformationId(informationId);
        if (danmoInformationMaps.size() != 0) {
            DanmoInformation danmoInformation = danmoInformationMapper.selectDanmoInformationById(informationId);
            if (danmoInformation.getViews() == null){
                danmoInformation.setViews(0L);
            }
            danmoInformation.setViews(danmoInformation.getViews() + 1);
            danmoInformationMapper.updateDanmoInformation(danmoInformation);
        }
        return danmoInformationMaps;
    }
}
